﻿#nullable enable

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Volo.Abp.Domain.Entities;

namespace PHMEE.EnergyEfficiency;

public class TimeSeriesDataLog : Entity<Guid>
{
    /// <summary>
    /// 时间戳
    /// </summary>
    public DateTime Ts { get; set; }

    /// <summary>
    /// 船舶 Id
    /// </summary>
    public Guid VesselId { get; set; }

    /// <summary>
    /// 同步的数据类型
    /// </summary>
    public SyncDataType SyncDataType { get; set; }

    /// <summary>
    /// 数据操作类型
    /// </summary>
    public OperationType OperationType { get; set; }

    /// <summary>
    /// 操作时间，对应 LastModifiedTime 或删除数据的时间
    /// </summary>
    public DateTime OperationTime { get; set; }

    /// <summary>
    /// 是否已同步完成（接收到岸端的 response）
    /// </summary>
    public bool IsSynced { get; set; }

    /// <summary>
    /// 实际数据，LA 或 Br
    /// </summary>
    public string Datum { get; set; } = "";

    public TimeSeriesDataLog(Guid id, Guid vesselId) : base(id)
    {
        VesselId = vesselId;
    }
}

public enum OperationType
{
    Insert = 1,
    Delete = 2,
}

public static class DataSyncJsonSerializerExtensions
{
    public static JsonSerializerOptions Options = new()
    {
        WriteIndented = false, // 禁用缩进
        DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, // 忽略空值
        // PropertyNamingPolicy = JsonNamingPolicy.CamelCase, // 使用驼峰命名可以略微减少长度
    };
}